using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Geomatrix
{
    class PlayGame
    {
        Texture2D _geomTex;
        Texture2D _crossTex;
        Texture2D _helpTex;
        Player player;

        Help helper;

        bool isPlaying;

        public PlayGame(Texture2D geomTex, Texture2D crossTex, Texture2D helpTex, Texture2D butTex)
        {
            isPlaying = false;
            player = new Player(new Vector2(0, 0)); //Create a temporary player, this gets overwritten when the game is started.
            _geomTex = geomTex;
            _crossTex = crossTex;
            _helpTex = helpTex;

            helper = new Help(_helpTex, butTex, "This is really helpful right?");
        }

        public int Update(TouchCollection tc)
        {
            int flag = helper.Update(tc);
            if (flag == 1)
                return 1;
            else if (flag == 2)
                return 2;

            if (HasWon())
                return 1;
            return 0; //If true is returned than end game.
        }

        public void Draw(SpriteBatch sb)
        {
            //Draw Grid
            DrawGrid(sb);

            sb.Draw(_geomTex, new Vector2(28, 49), Color.Lime);
            sb.Draw(_geomTex, new Vector2(28, 177), Color.Lime);
            sb.Draw(_geomTex, new Vector2(68, 49), Color.Lime);
            sb.Draw(_geomTex, new Vector2(68, 177), Color.Lime);

            helper.Draw(sb);
        }

        public void DrawGrid(SpriteBatch sb)
        {
            int xOff = (int)player.GetPosition().X % 128 - 128;
            int yOff = (int)player.GetPosition().Y % 128 - 128;

            for (int x = xOff; x < 400; x += 128)
            {
                for (int y = yOff; y < 608; y += 128)
                {
                    sb.Draw(_crossTex, new Vector2(x, y), Color.Lime);
                }
            }
        }

        public Boolean HasWon()
        {
            //for (int index = 0; index < GeomList.Length; ++index)
            {
                return false;
            }

            return true;
        }
    }
}